﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace browserplayform
{
    public partial class webbrowserform : Form
    {
        public WebBrowser webbrowser;
        //private Form childForm;
        public Thread wbtread;

        public webbrowserform()
        {
            InitializeComponent();
            
        }

        private void button_go_Click(object sender, EventArgs e)
        {
            try {
                string url_tmp = this.richTextBox_url.Text;
                if (url_tmp != "")
                {
                    this.Controls.Add(webbrowser);
                    this.webbrowser.Navigate(url_tmp);
                    this.webbrowser.Show();
                    //if (this.wbtread != null)
                    //{
                    //    //this.wbtread.Abort();
                    //}
                    
                    ////
                    //this.wbtread = new Thread(new ParameterizedThreadStart(this.webthread));
                    //this.wbtread.SetApartmentState(ApartmentState.STA);
                    //wbtread.IsBackground = true;
                    //wbtread.Start(url_tmp);
                    

                }
                
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        public void webthread(object sender)
        {
            this.webbrowser = new WebBrowser();
            this.webbrowser.ScriptErrorsSuppressed = true;
            this.webbrowser.Dock = DockStyle.Fill;
            this.webbrowser.Navigate(sender.ToString());
            this.webbrowser.Show();
            //
             
            Form childForm = new Form();
            childForm.Controls.Add(this.webbrowser);
            
            childForm.ShowDialog();


        }


        private void webbrowserform_Load(object sender, EventArgs e)
        {
            try
            {
                this.webbrowser = new WebBrowser();
                this.webbrowser.ScriptErrorsSuppressed = true;
                this.webbrowser.Dock = DockStyle.Fill;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
    }
}
